<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
	+ request.getServerName() + ":" + request.getServerPort()
	+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>Mua~亲亲宠管理平台·权限管理</title>
<link rel="stylesheet" href="css/style.css" />

<link rel="stylesheet" href="css/bootstrap.css" />
<link rel="stylesheet" href="css/bootstrap-table.min.css" />

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>

<script type="text/javascript" src="js/bootstrap-table.min.js"></script>
<script type="text/javascript" src="js/bootstrap-table-zh-CN.min.js"></script>
</head>

<body>
	<%@ include file="/WEB-INF/jsp/mgnt/mgntTop.jspf"%>
	<div class="container  col-sm-offset-1  col-sm-10">
		<div class="page-header">
			<h3>
				权限管理<small></small>
			</h3>
		</div>
		<div class="container  col-sm-offset-1  col-sm-10">
			<div id="toolbar">
				<button id="btn_add" type="button" class="btn btn-default"
					onclick="add()">
					<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
				</button>
			</div>
			<table id="privilegeTable" class="table table-striped">

			</table>
		</div>
	</div>
	<script type="text/javascript">
		$('#privilegeTable')
				.bootstrapTable(
						{
							url : 'admin/listPrivilege.do',
							method : "post",
							pagination : true, // 是否显示分页（*）
							sidePagination : "client", // 分页方式：client客户端分页，server服务端分页（*）
							pageNumber : 1, // 初始化加载第一页，默认第一页
							pageSize : 10, // 每页的记录行数（*）
							pageList : [ 5, 10, 25 ], // 可供选择的每页的行数（*）
							toolbar : "#toolbar",
							search : true,
							responseHandler : function(res) {
								return res.privilegeList;
							},
							columns : [
									{
										title : '序号',
										field : 'no',
										align : 'center',
										valign : 'middle',
										formatter : function(value, row, index) {
											return index + 1;
										}
									},
									{
										title : '权限名称',
										field : 'privilegename',
										align : 'center',
										valign : 'middle'
									},
									{
										title : '权限路径',
										field : 'url',
										align : 'center',
										valign : 'middle'
									},
									{
										title : '描述',
										field : 'description',
										align : 'center',
										valign : 'middle'
									},
									{
										title : '状态',
										field : 'state',
										align : 'center',
										valign : 'middle',
										formatter : function(value) {
											if (value == '0') {
												return "停用";
											} else if (value == '1') {
												return "在用";
											}
										}
									},
									{
										title : '操作',
										align : 'center',
										formatter : function(value, row, index) {
											var editbtn = '<a href="admin/editPrivilege.do?id='
													+ row.id
													+ '"><button class="btn btn-sm  btn-info">编辑</button></a> ';
											var deletebtn = '<button class="btn btn-sm  btn-info" onclick="deletePrivilege('
													+ row.id + ')">删除</button>';
											return editbtn + deletebtn;
										}
									} ]
						});
		function deletePrivilege(id) {
			$.ajax({
				url : "admin/deletePrivilege.do",
				type : "POST",
				data : {
					"id" : id
				},
				success : function(result) {
					if (result.msg == 'error') {
						$(".modal-body").html(result.errorMsg);
						$("#topModal").modal("show");
					} else if (result.msg == 'success') {
						$(".modal-body").html("删除成功");
						$("#topModal").modal("show");
						refresh();
					}
				}
			});
		}
		function refresh() {
			$('#privilegeTable').bootstrapTable('refresh');
		}
		function add() {
			window.location.href = "admin/newPrivilege.do";
		}
	</script>
</body>
</html>
